﻿<Window x:Class="ProcessMonitor.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Process Monitor"
        Width="700" Height="500">
    <Grid>
        <Grid.Resources>
            <Style TargetType="TextBlock">
                <Setter Property="Margin" Value="5" />
                <Setter Property="HorizontalAlignment" Value="Right" />
                <Setter Property="VerticalAlignment" Value="Center" />
            </Style>
            <Style TargetType="TextBox">
                <Setter Property="Margin" Value="5" />
            </Style>
        </Grid.Resources>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <StackPanel Orientation="Horizontal">
            <Button Content="Update Process List" Padding="5" Margin="5" Click="UpdateButton_Click" />
            <Button Content="Config" Padding="5" Margin="5" Click="ConfigButton_Click" />
        </StackPanel>
        <ListView Grid.Row="1" Name="listViewProcess" Margin="5" ItemsSource="{Binding Path=ProcessViewSource.View}"
                  SelectionChanged="listViewProcess_SelectionChanged">
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="ID" DisplayMemberBinding="{Binding Path=Id}" />
                    <GridViewColumn Header="Process name" DisplayMemberBinding="{Binding Path=ProcessName, Converter={StaticResource ResourceKey=debugConverter}}" />
                    <GridViewColumn Header="Total process time" DisplayMemberBinding="{Binding Path=TotalProcessorTime}" />
                </GridView>
            </ListView.View>
        </ListView>
        <ListView Grid.Row="1" Name="listViewThreads" Grid.Column="1" Margin="5">
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="Thread ID" DisplayMemberBinding="{Binding Path=Id}" />
                    <GridViewColumn Header="Total Process Time" DisplayMemberBinding="{Binding Path=TotalProcessorTime}" />
                    <GridViewColumn Header="State" DisplayMemberBinding="{Binding Path=ThreadState}" />
                </GridView>
            </ListView.View>
        </ListView>
        <Grid Grid.Row="2" Margin="5">
            <GroupBox Header="Process Info" Name="groupBoxProcessInfo">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <TextBlock Grid.Row="0" Text="PID:" />
                    <TextBlock Grid.Row="1" Text="Memory:" />
                    <TextBlock Grid.Row="2" Text="Total processor time:" />
                    <TextBlock Grid.Row="3" Text="Number of threads:" />
                    <TextBlock Grid.Row="4" Text="Disk Read (bytes):" />
                    <TextBlock Grid.Row="5" Text="Disk Write (bytes):" />
                    <TextBlock Grid.Row="6" Text="Application Pool:" />
                    <TextBox x:Name="txtProcessId" Grid.Row="0" Grid.Column="1" Text="{Binding ElementName=listViewProcess, Mode=OneWay, Path=SelectedItem.Id}" />
                    <TextBox x:Name="txtProcessMemory" Grid.Row="1" Grid.Column="1" Text="{Binding ElementName=listViewProcess, Mode=OneWay, Path=SelectedItem.WorkingSet64}" />
                    <TextBox x:Name="txtProcessTime" Grid.Row="2" Grid.Column="1" Text="{Binding ElementName=listViewProcess, Mode=OneWay, Path=SelectedItem.TotalProcessorTime}" />
                    <TextBox x:Name="txtProcessThreads" Grid.Row="3" Grid.Column="1" Text="{Binding ElementName=listViewProcess, Mode=OneWay, Path=SelectedItem.Threads.Count}" />
                    <TextBox x:Name="txtProcessDiskRead" Grid.Row="4" Grid.Column="1" Text="{Binding Path=PerformanceCounterRead.RawValue}" />
                    <TextBox x:Name="txtProcessDiskWrite" Grid.Row="5" Grid.Column="1" Text="{Binding Path=PerformanceCounterWrite.RawValue}" />
                    <TextBox x:Name="txtProcessAppPool" Grid.Row="6" Grid.Column="1" />
                </Grid>
            </GroupBox>
        </Grid>
        <Grid Grid.Row="2" Grid.Column="1" Name="gridThreadInfo">
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <GroupBox Header="Thread Info" Name="groupBoxThreadInfo" Margin="5">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <TextBlock Grid.Row="0" Text="TID:" />
                    <TextBlock Grid.Row="1" Text="Current priority:" />
                    <TextBlock Grid.Row="2" Text="Thread state:" />
                    <TextBlock Grid.Row="3" Text="Total processor time:" />
                    <TextBox x:Name="txtThreadId" Grid.Row="0" Grid.Column="1" Text="{Binding ElementName=listViewThreads, Mode=OneWay, Path=SelectedItem.Id}" />
                    <TextBox x:Name="txtThreadPriority" Grid.Row="1" Grid.Column="1" Text="{Binding ElementName=listViewThreads, Mode=OneWay, Path=SelectedItem.CurrentPriority}" />
                    <TextBox x:Name="txtThreadState" Grid.Row="2" Grid.Column="1" Text="{Binding ElementName=listViewThreads, Mode=OneWay, Path=SelectedItem.ThreadState}" />
                    <TextBox x:Name="txtThreadTime" Grid.Row="3" Grid.Column="1" Text="{Binding ElementName=listViewThreads, Mode=OneWay, Path=SelectedItem.TotalProcessorTime}" />
                </Grid>
            </GroupBox>
            <GroupBox Grid.Row="1" Header="Billing" Name="groupBoxBilling" Margin="5">
                <Grid Margin="5">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <TextBlock Grid.Row="0" Text="Total: $ " />
                    <TextBox x:Name="txtBillingTotal" Grid.Row="0" Grid.Column="1" Text="{Binding Path=Total}" />
                </Grid>
            </GroupBox>
        </Grid>
    </Grid>
</Window>
